package service

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"wechat01/basic/config"
	"wechat01/handler/model"
	"wechat01/handler/request"
)

func GetMessage(c *gin.Context) {
	var form request.GetMessage
	if err := c.ShouldBind(&form); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": "参数错误"})
		return
	}
	var message model.Message
	list, err := message.GetMessage(config.DB, form.Userid, form.FriendId)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": "查询聊天记录失败"})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "查询聊天记录成功",
		"data": gin.H{
			"list": list,
		},
	})
	return
}
